package com.sojoys.artifact.config;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.sojoys.artifact.core.IModule;

public abstract class Modules {
	private final Map<Byte,IModule> modules = new ConcurrentHashMap<>();

	public Modules add(byte key,IModule module) {
		if (module == null) {
			throw new IllegalArgumentException("handler can not be null");
		}
		modules.put(key, module);
		return this;
	}

	@SuppressWarnings("unchecked")
	public <T> T getModule(Byte key,Class<T> clz) {
		return (T) modules.get(key);
	}
	
	public Map<Byte, IModule> getModules() {
		return modules;
	}

	public abstract Modules config();
	
	public void add(Modules handlers){
		getModules().putAll(handlers.config().getModules());
	}
}
